package com.bootdo.blog.dao;

import com.bootdo.blog.domain.OperatorDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface OperatorMapper {

	@Select("select `operator_id`, `credit_code`, `title`, `address`, `legal_representative`, `nature`, `classification`, `linkman`, `telephone`, `brief_introduction`, `flag` from tb_operator where operator_id = #{id}")
	OperatorDO get(Integer operatorId);
	
	@Select("<script>" +
	"select * from tb_operator " + 
			"<where>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  		  "<if test=\"creditCode != null and creditCode != ''\">"+ "and credit_code = #{creditCode} " + "</if>" + 
		  		  "<if test=\"title != null and title != ''\">"+ "and title = #{title} " + "</if>" + 
		  		  "<if test=\"address != null and address != ''\">"+ "and address = #{address} " + "</if>" + 
		  		  "<if test=\"legalRepresentative != null and legalRepresentative != ''\">"+ "and legal_representative = #{legalRepresentative} " + "</if>" + 
		  		  "<if test=\"nature != null and nature != ''\">"+ "and nature = #{nature} " + "</if>" + 
		  		  "<if test=\"classification != null and classification != ''\">"+ "and classification = #{classification} " + "</if>" + 
		  		  "<if test=\"linkman != null and linkman != ''\">"+ "and linkman = #{linkman} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"briefIntroduction != null and briefIntroduction != ''\">"+ "and brief_introduction = #{briefIntroduction} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by operator_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<OperatorDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_operator " + 
			"<where>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  		  "<if test=\"creditCode != null and creditCode != ''\">"+ "and credit_code = #{creditCode} " + "</if>" + 
		  		  "<if test=\"title != null and title != ''\">"+ "and title = #{title} " + "</if>" + 
		  		  "<if test=\"address != null and address != ''\">"+ "and address = #{address} " + "</if>" + 
		  		  "<if test=\"legalRepresentative != null and legalRepresentative != ''\">"+ "and legal_representative = #{legalRepresentative} " + "</if>" + 
		  		  "<if test=\"nature != null and nature != ''\">"+ "and nature = #{nature} " + "</if>" + 
		  		  "<if test=\"classification != null and classification != ''\">"+ "and classification = #{classification} " + "</if>" + 
		  		  "<if test=\"linkman != null and linkman != ''\">"+ "and linkman = #{linkman} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"briefIntroduction != null and briefIntroduction != ''\">"+ "and brief_introduction = #{briefIntroduction} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_operator (`credit_code`, `title`, `address`, `legal_representative`, `nature`, `classification`, `linkman`, `telephone`, `brief_introduction`, `flag`)"
	+ "values (#{creditCode}, #{title}, #{address}, #{legalRepresentative}, #{nature}, #{classification}, #{linkman}, #{telephone}, #{briefIntroduction}, #{flag})")
	int save(OperatorDO operator);
	
	@Update("<script>"+ 
			"update tb_operator " + 
					"<set>" + 
		            "<if test=\"operatorId != null\">`operator_id` = #{operatorId}, </if>" + 
                    "<if test=\"creditCode != null\">`credit_code` = #{creditCode}, </if>" + 
                    "<if test=\"title != null\">`title` = #{title}, </if>" + 
                    "<if test=\"address != null\">`address` = #{address}, </if>" + 
                    "<if test=\"legalRepresentative != null\">`legal_representative` = #{legalRepresentative}, </if>" + 
                    "<if test=\"nature != null\">`nature` = #{nature}, </if>" + 
                    "<if test=\"classification != null\">`classification` = #{classification}, </if>" + 
                    "<if test=\"linkman != null\">`linkman` = #{linkman}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
                    "<if test=\"briefIntroduction != null\">`brief_introduction` = #{briefIntroduction}, </if>" + 
                    "<if test=\"flag != null\">`flag` = #{flag}, </if>" + 
          					"</set>" + 
					"where operator_id = #{operatorId}"+
			"</script>")
	int update(OperatorDO operator);
	
	@Delete("delete from tb_operator where operator_id =#{operatorId}")
	int remove(Integer operator_id);
	
	@Delete("<script>"+ 
			"delete from tb_operator where operator_id in " + 
					"<foreach item=\"operatorId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{operatorId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] operatorIds);
}
